<?php
/**
 * Created by PhpStorm.
 * User: JennyWang
 * Date: 2017/4/10
 * Time: 20:49
 */

namespace App\Exceptions;

abstract class AdminException extends \Exception
{
    protected $error;
    protected $code;
    protected $debug;
    
    public function __construct(
        $code  = -1,
        $error = "未定义错误 | undefined error" ,
        $debug = false
    ) {
        $this->code = $code;
        $this->error = $error;
        $this->debug = $debug;
    }

    public function response()
    {
        $res_arr = [
            'code' => $this->code,
            'error' => $this->error,
        ];

        if ( $this->debug || $this->code === -1 ) {
            $res_arr['trace'] = $this->getTrace();
        };

        return response($res_arr , 200);
    }
}